/*
  接口应用场景：
    1. 一些第三方包或框架底层源码中有大量的接口类型
    2. 提供方法的对象类型的参数时使用
    3. 为多个同类别的类提供统一的方法和属性声明
*/

/* interface Product {
  name: string,
  price: number,
  account: number
} */

type Product = {
  name: string;
  price: number;
  account: number;
  // 接口只有声明，没有实现
  buy(): void;
};

let p: Product = {
  name: "phone",
  price: 100,
  account: 10,
  buy() {
    console.log("first");
  },
};

// 接口继承
interface Pet {
  name: string;
  love: number;
  health: number;
  toHealth(): void;
}

interface Dog extends Pet {
  strain: string;
  guradHome(): void;
}
// 接口用于具体对象的类型
let dog: Dog = {
  name: "ww",
  love: 100,
  health: 12,
  toHealth() {
    console.log("toHealth");
  },
  strain: "旺财",
  guradHome() {
    console.log("guradHome");
  },
};

// 接口实现
interface List {
  add(): void;
  remove(): void;
}

class ArrayList implements List {
  add(): void {
    console.log("ArrayList add");
  }
  remove(): void {
    console.log("ArrayList move");
  }
}

class LinkedList implements List {
  add(): void {
    console.log("LinkedList add");
  }
  remove(): void {
    console.log("LinkedList remove");
  }
}

export {};
